﻿using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace FastExecutor.Base.Model
{
    public class ReturnValue : JsonResult
    {
        private Hashtable table;
        public ReturnValue()
        {
            table = new Hashtable();
            table.Add("code", 0);
            table.Add("msg", "执行成功！");
        }

        public void Add(string Key, Object Value)
        {
            if (!table.Contains(Key))
            {
                table.Add(Key, Value);
            }
            else
            {
                table[Key] = Value;
            }
        }

        public Object Get(string Key)
        {
            return table[Key];
        }

        public override void ExecuteResult(ControllerContext context)
        {
            var json = JsonConvert.SerializeObject(table,
                Formatting.Indented,
                new JsonSerializerSettings
                {
                    DateFormatString = "yyyy-MM-dd HH:mm:ss"
                }
                );
            context.HttpContext.Response.Write(json);
        }
    }
}
